<jsp:include page="../../header.jsp">
			<jsp:param value="item5" name="item"/>
</jsp:include>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<section class="content">
	<section class="widget"  id="department" >
		<header>
			<span class="icon">&#128196;</span>
			<hgroup>
				<h1>差旅管理</h1>
				<h2>路线制定</h2>
			</hgroup>
		</header>
		<s:if test="isingroup==0">
			<div class="content">
				<div class="orange">
				<p><strong>为什么我不能制订路线？(╯‵□′)╯︵┻━┻<br/>
				<br/>
				亲(づ￣3￣)づ╭❤～，<br/>
				你还不属于任何一个用户组或者你所在用户组不具有出差标准，快叫管理员去处理吧~┬—┬ノ('-'ノ)<br/></strong></p>
				</div>
			</div>
		</s:if>
		<s:else>
			<div class="content">
	
			<div id="back"><a href="route!showRouteList" >查看出差记录表</a></div>
		
			<div class="toppart">
				<div class="mapleft">
					<div class="search">
								<label>搜索:</label><font color="#dd0000">(设定起终点前需先通过搜索列表点击地点!)	</font><br/>
								<input type="text" id="searchKey" />
								<input type="button"  class="button white" onClick="localsearch.search(document.getElementById('searchKey').value,7)" value="搜索"/>
								<div>
									<input type="button"  class="button white" value="设为起点" onclick=setstartdest(0) />
									<input type="button"  class="button white" value="设为终点" onclick=setstartdest(1) />
									<input type="button"  class="button white" id="query" value="路线长度获取" onclick="route()" />
								</div>
					</div>
				
					<div id="resultDiv" class="result">
						<div id="searchDiv"></div>
							<input type="button"  class="button white" value="第一页" onClick="localsearch.firstPage()"/>
					        <input type="button"  class="button white" value="上一页" onClick="localsearch.previousPage()"/>
					        <input type="button" class="button white" value="下一页" onClick="localsearch.nextPage()"/>
					        <input type="button" class="button white" value="最后一页" onClick="localsearch.lastPage()"/>
					        <br/>
							转到第<input type="text" value="1" id="pageId" size="3"  onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "/>页
					        <input type="button" class="button white" onClick="gotopage();" value="转到"/>
					</div>
					
					<div class="submit">
							<ul id="routeMsg">
								<li><label>起点：</label><input type="text" id="startplace" name="startplace" readonly="true" />
										<label>终点：</label><input type="text" id="endplace" name="endplace" readonly="true" /></li>
								<li><label>天数：</label><input type="text" id="daytime" name="daytime"  onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "/>
										<label>距离：</label><input type="text" id="distance" name="distance" readonly="true"/>公里</li>
								<li><span>你的差旅标准是：</span></li>
								<li><label>交通：</label>
											<s:property value="userts.traffic.traffic" />，
											<s:property value="userts.traffic.standard" />
									&emsp;
									<label>费用：</label>
										<s:property value="userts.traffic.price" />元/公里
								</li>
								<li><label>住宿：</label>
										<s:property value="userts.hotel.hotel" />
									&emsp;
									<label>费用：</label>
										<s:property value="userts.hotel.price" />元/天
								</li>
	
							</ul>
						<input type="button"  class="button white" value="提交" onclick=addItem() />
					</div>
				</div>
							
				<div class="mapright" id="map">
				</div>
			</div>
	   
		  	<div class="underpart">
		  		<h1>出差条目：<s:if test="travelOrder!=null">你的出差单号为:<s:property value="travelOrder" /></s:if></h1>
		  		<br>
		  		<form id="sform" method="post">
		  			开始时间：
		  			<s:if test="alterstarttime!=null">
		  				<input type="text" readonly="true" id="starttime" name="alterstarttime" value="<s:property value='alterstarttime' />" onclick="return showCalendar('starttime', 'y-mm-dd');" />
		  			</s:if>
		  			<s:else>
		  				<input type="text" readonly="true" id="starttime" name="starttime" onclick="return showCalendar('starttime', 'y-mm-dd');" />
		  			</s:else>
		  			结束时间：
		  			<s:if test="alterendtime!=null">
		  				<input type="text" id="endtime" name="alterendtime" value="<s:property value='alterendtime' />" readonly="true" />
		  			</s:if>
		  			<s:else>
		  				<input type="text" id="endtime" name="endtime" readonly="true" />
		  			</s:else>
		  			
		  			<div class="btlist">
		  			</br>
		  				分支条目：
		  				<table id="myTable"  >
		  					<tr>
		  						<th>起点</th> <th>终点</th> <th>天数</th> <th>距离</th><th>操作</th>
		  					</tr>
		  					<s:if test="(routeList!=null)&&(routeList.size()>0)">
		  						<s:iterator value="routeList" id="row" status="status">
		  							<tr class="btlistitem">
						    			<td><input type="hidden" name="routeList[<s:property value='#status.index' />].startPlace" value="<s:property value='#row.startPlace' />" /><s:property value="#row.startPlace" /></td>
						    			<td><input type="hidden" name="routeList[<s:property value='#status.index' />].endPlace" value="<s:property value='#row.endPlace' />" /><s:property value="#row.endPlace" /></td>
						    			<td><input type="hidden" name="routeList[<s:property value='#status.index' />].time" value="<s:property value='#row.time' />" /><s:property value="#row.time" /></td>
						    			<td><input type="hidden" name="routeList[<s:property value='#status.index' />].distance" value="<s:property value='#row.distance' />" /><s:property value="#row.distance" /></td>
						    			<td><input type="button" name="deletebt" class="button white" value="删除" onclick=deletetableitem(this) /></td>
		    						</tr>
		  						</s:iterator>
		  					</s:if>
		  				</table>
		  			</div>
		  			<!-- <input type="submit" value="提交出差路线" /> -->
		  			<s:if test="travelOrder!=null">
		  				<input type="button"  class="button white" value="提交修改" onclick=submitform(1,'<s:property value="travelOrder" />') />
		  			</s:if>
		  			<s:else>
		  				<input type="button"  class="button white" value="提交出差路线" onclick=submitform(0) />
		  			</s:else>
		  			<input type="button"  class="button white" value="重设" onclick=resetroute() />
		  		</form>
		  	</div>
	    
	    	</div>
	    	</section>
	    </s:else>
    <script type="text/javascript" src="http://api.tianditu.com/js/maps.js"></script>
	<script type="text/javascript" src="http://api.tianditu.com/js/service.js"></script> 
    <script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
	<script type="text/javascript" src="js/ajax.js"></script>
	
	<script type="text/javascript" src="js/calendar.js" ></script>  
	<script type="text/javascript" src="js/calendar-zh.js" ></script>
	<script type="text/javascript" src="js/calendar-setup.js"></script>
	<script type="text/javascript">
			var aMarker = ["images/bus/start.png","images/bus/end.png"];	//标记图地址表
			var markerS=null,markerE=null;	//标记
			var map = new TMap("map");
			var menu = new TContextMenu();
			var localsearch;
			
			
			//try
			var locpoint;
			var startco;	//起点坐标
			var endco;	//终点坐标
			var trindex;
			var duration;	//持续时间
				
			window.onload=function(){
				trindex = document.getElementById("myTable").rows.length-1;
				duration = 0;
				//alert(trindex);
				if(trindex>0){
					for(var i=1;i<trindex+1;i++){	//修改时因为已经有数据！
						duration += parseInt(document.getElementById("myTable").rows[i].cells[2].firstChild.value);
					}
				}
				//alert(trindex);
				//构造地图，并添加地图基本要素。
				map.centerAndZoom(new TLngLat(113.87124, 22.90693), 15);
				map.setZoomLevels([7,8,9,10,11,12,13,14,15,16]);	//设置地图缩放大小为省
				map.enableHandleMouseScroll();
				map.enableInertia();
				map.enableHandleKeyboard();
				map.enableDoubleClickZoom();
				var config = {
					//type : "TMAP_NAVIGATION_CONTROL_LARGE",
					type : "TMAP_NAVIGATION_CONTROL_ZOOMANDSLIDER",
					anchor : "TMAP_ANCHOR_TOP_RIGHT",
					offset : [ 0, 0 ],
					showZoomInfo : false
				};
				control = new TNavigationControl(config);
				map.addControl(control);
				
				//搜索
				var searchconfig={
					pageCapacity:5,	//每页显示数量
					onSearchComplete:localSearchResult	//接收数据的回调函数
				};
				localsearch=new TLocalSearch(map,searchconfig);
			}
			
			function localSearchResult(result) { 
				//清空地图及搜索列表 
				clearAll(); 
				//添加提示词 
				//prompt(result); 
				//根据返回类型解析搜索结果 
				switch(parseInt(result.getResultType())){ 
					case 1:
					case 3:
						//解析点数据结果 
						if(result.getCount()==0)
							alert("搜索无结果，请重新搜索");
						else
							pois(result.getPois()); 
						break; 
					case 2:
						alert("因该地点结果太多，请详细描述");	//提示完善关键字
						break; 
					default:
						alert("搜索无结果，请重新搜索");	//搜索失败提示
						break;
				}
			} 
			
			//解析点数据结果
			function pois(obj){ 
				if(obj) { 
					//显示搜索列表 
					var divMarker = document.createElement("div"); 
					//坐标数组，设置最佳比例尺时会用到 
					var zoomArr = []; 
					for(var i=0;i<obj.length;i++) { 
						//闭包 
						(function(i){ 
							//名称 
							var name = obj[i].name; 
							//地址 
							var address = obj[i].address; 
							//坐标 
							var lnglatArr = obj[i].lonlat.split(" "); 
							var lnglat = new TLngLat(lnglatArr[0],lnglatArr[1]);		
							
							var winHtml = "地址:"+address; 
							 
							//创建标注对象 
							var marker = new TMarker(lnglat); 
							//地图上添加标注点 
							map.addOverLay(marker); 
							//注册标注点的点击事件 
							TEvent.bind(marker,"click",marker,function(){ 
								var info = this.openInfoWinHtml(winHtml); 
								info.setTitle(name); 
							}); 
							zoomArr.push(lnglat); 
							 
							//在页面上显示搜索的列表 
							var a = document.createElement("a"); 
							a.href = "javascript://"; 
							a.innerHTML = name; 
							a.onclick = function(){
								//try
								locpoint = lnglat;
								showPosition(marker,name,winHtml);
								document.getElementById("searchKey").value=name;
							} 
							divMarker.appendChild(document.createTextNode((i+1)+".")); 
							divMarker.appendChild(a); 
							divMarker.appendChild(document.createElement("br")); 
						})(i); 
					} 
					//显示地图的最佳级别 
					map.setViewport(zoomArr); 
					//显示搜索结果 
					divMarker.appendChild(document.createTextNode('共'+localsearch.getCountNumber()+'条记录，分'+localsearch.getCountPage()+'页,当前第'+localsearch.getPageIndex()+'页')); 
					document.getElementById("searchDiv").appendChild(divMarker); 
					document.getElementById("resultDiv").style.display = "block"; 
				}else{
					/*alert("搜索无数据");*/
				}
			}

			//将地点变为起终点
			function setstartdest(type){
				if(type==0){//起点
					//try
					startco=locpoint.getLng()+","+locpoint.getLat();
					$("#startplace").val($("#searchKey").val());	//赋给起点text
					setPoint(locpoint,"start");
				}
				else if(type==1){
					endco=locpoint.getLng()+","+locpoint.getLat();
					$("#endplace").val($("#searchKey").val());	//赋给终点text
					setPoint(locpoint,"dest");
				}
			}
			
			//显示信息框 
			function showPosition(marker,name,winHtml) { 
				var info = marker.openInfoWinHtml(winHtml); 
				info.setTitle(name); 
			} 
			
			//快速通过id获取对象方法。
			/*function $(id){
				return document.getElementById(id);
			}*/
			
			
			//选取起终点信息。鼠标右键设置
			function setPoint(lnglat,type){
				//把右键获取的起终点经纬度回填到输入框中 
				if(type=="start"){  
					//删除已经添加到地图中的起点图标 
					if(markerS!=null){ 
						map.removeOverLay(markerS); 
						markerS = null; 
					} 
					//调用创建marker方法 
					markerS = createFeature(lnglat.getLng()+","+lnglat.getLat(),"start"); 
				}else if(type=="dest"){ 
					//删除已经添加到地图中的起点图标 
					if(markerE!=null){ 
						map.removeOverLay(markerE); 
						markerE=null; 
					} 
					//调用创建marker方法 
					markerE = createFeature(lnglat.getLng()+","+lnglat.getLat(),"dest"); 
				} 
			}
			
			
			//开始路径规划
			function route(){
				//清除上一次的内容。
				clearAll();
				var start = startco;//起点坐标值
				var dest = endco;//终点坐标值
				$.ajax({
					url: "route!getMapResult.action",
					data: "routeStr={'orig':'"+start+"','dest':'"+dest+"','style':'1'}",
					method: "get",
					dataType: "json",
					contentType: "application/json",
					success: function(mapMessage){
						//var result = req.responseText;
						var result = mapMessage;
						//路径规划只支持国内，有国外时不法规划，返回此内容。
						if(result=="<result></result>"){
							alert("由于缺少部分路网信息，暂时无法提供方案。");
							return;
						}
						//解析结果集
						resolveResult(result,1);	//默认为1
					},
					error: function(mapMessage){
						alert("网络问题请重试")
					}
				});
			}
			
			
			//解析领规划信息。并显示。
			function resolveResult(result,style){
				//将xml变成json格式。
				var obj = parseXmlToObj(result,style);
				
				var routelatlon = obj.routelatlon
				var distance = obj.distance;//路程，单位公里
				
				var startLonlat = startco;
				var destLonlat = endco;
				var startFeature = createFeature(startLonlat,"start");	//起点图标
				var destFeature = createFeature(destLonlat,"dest");	//终点图标
				
				var distance_show = Math.round(distance);
				var html = "<div class='route_scheme_box'>";
				html += "<div class='total_mileage'>总里程：约<span>"+distance_show+"</span>公里</div>";
				html += "</div>";
				//设为startplace,endplace,distance的值
				//$("#startplace").val(startLonlat);
				//$("#endplace").val(destLonlat);
				if(distance_show==0)	distance_show=1;
				$("#distance").val(distance_show);
				//
				$("#list").html(html);
				//显示路线
				showRouteLineFeature(routelatlon,startFeature,destFeature);
			}
			
			
			//在地图上显示路线。
			function showRouteLineFeature(routelatlon,startFeature,destFeature){
				var lonlats = routelatlon.split(";");
				var lonlatsLength = lonlats.length;
				var midFeatures = [];
				var routeLine = null;
				if(lonlatsLength > 0){
					var lineArr = [];
					for(var i = 0 ; i < lonlatsLength ; i++){
						var lonlat = lonlats[i];
						if(lonlat == ""){
							continue;
						}
						var lon = lonlat.split(",")[0];
						var lat = lonlat.split(",")[1];
						var lnglat = new TLngLat(lon,lat);
						lineArr.push(lnglat);
					}
					var style = {
							strokeColor:"#ED2C2F",
							strokeWeight:5,
							strokeOpacity:0.8
					}
					routeLine = new TPolyline(lineArr,style);
				}
				map.addOverLay(routeLine);
				map.addOverLay(startFeature);
				map.addOverLay(destFeature);
				if(midFeatures.length > 0){
					for(var i = 0 ; i < midFeatures.length ; i++){
						var feature = midFeatures[i];
						map.addOverLay(feature);
					}
				}
				map.setViewport(lineArr);
				
			}
			
			//解析xml
			function parseXmlToObj(result,style){
				//转化为dom对象解析此xml，转为为json对象。
				var xmlDoc = loadXML(result);
				var distance = xmlDoc.getElementsByTagName("distance")[0].firstChild.nodeValue;
				var duration = xmlDoc.getElementsByTagName("duration")[0].firstChild.nodeValue;
				var routelatlon;
				if(document.all){
					routelatlon = xmlDoc.getElementsByTagName("routelatlon")[0].firstChild.nodeValue;
				}else{
					routelatlon = xmlDoc.getElementsByTagName("routelatlon")[0].textContent;
				}
				var parameters = xmlDoc.getElementsByTagName("parameters")[0];
				var start = parameters.getElementsByTagName("orig")[0].firstChild.nodeValue;
				var dest = parameters.getElementsByTagName("dest")[0].firstChild.nodeValue;
				var mid = "";
				if(parameters.getElementsByTagName("mid")[0]&&parameters.getElementsByTagName("mid")[0].firstChild){
					mid = parameters.getElementsByTagName("mid")[0].firstChild.nodeValue;
				}
				var sty = parameters.getElementsByTagName("style")[0].firstChild.nodeValue;
				
				var routes = xmlDoc.getElementsByTagName("routes")[0];
				var items = routes.getElementsByTagName("item");
				var itemsLength = items.length;
				var strguide,signage="",streetName="",nextStreetName="",turnlatlon="";
				var routesArr = [];
				for(var i=0;i<itemsLength;i++){
					strguide = items[i].getElementsByTagName("strguide")[0].firstChild.nodeValue;
					if(items[i].getElementsByTagName("signage")[0].firstChild){
						signage = items[i].getElementsByTagName("signage")[0].firstChild.nodeValue;
					}
					if(items[i].getElementsByTagName("streetName")[0].firstChild){
						streetName = items[i].getElementsByTagName("streetName")[0].firstChild.nodeValue;
					}
					if(items[i].getElementsByTagName("nextStreetName")[0].firstChild){
						nextStreetName = items[i].getElementsByTagName("nextStreetName")[0].firstChild.nodeValue;
					}
					if(items[i].getElementsByTagName("turnlatlon")[0].firstChild){
						turnlatlon = items[i].getElementsByTagName("turnlatlon")[0].firstChild.nodeValue;
					}
					var routesObj = {
							strguide:strguide,
							signage:signage,
							streetName:streetName,
							nextStreetName:nextStreetName,
							turnlatlon:turnlatlon
					}
					routesArr.push(routesObj);
				}
				
				var simple = xmlDoc.getElementsByTagName("simple")[0];
				var sim_items = simple.getElementsByTagName("item");
				var sim_itemsLength = sim_items.length;
				var sim_strguide,streetNames="",lastStreetName="",linkStreetName="",sim_turnlatlon="",streetLatLon="",streetDistance="",segmentNumber="";
				var simpleArr = [];
				for(var i=0;i<sim_itemsLength;i++){
					sim_strguide = sim_items[i].getElementsByTagName("strguide")[0].firstChild.nodeValue;
					if(sim_items[i].getElementsByTagName("streetNames")[0].firstChild){
						streetNames = sim_items[i].getElementsByTagName("streetNames")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("lastStreetName")[0].firstChild){
						lastStreetName = sim_items[i].getElementsByTagName("lastStreetName")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("linkStreetName")[0].firstChild){
						linkStreetName = sim_items[i].getElementsByTagName("linkStreetName")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("turnlatlon")[0].firstChild){
						sim_turnlatlon = sim_items[i].getElementsByTagName("turnlatlon")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("streetLatLon")[0].firstChild){
						streetLatLon = sim_items[i].getElementsByTagName("streetLatLon")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("streetDistance")[0].firstChild){
						streetDistance = sim_items[i].getElementsByTagName("streetDistance")[0].firstChild.nodeValue;
					}
					if(sim_items[i].getElementsByTagName("segmentNumber")[0].firstChild){
						segmentNumber = sim_items[i].getElementsByTagName("segmentNumber")[0].firstChild.nodeValue;
					}
					var simpleObj = {
							strguide:sim_strguide,
							streetNames:streetNames,
							lastStreetName:lastStreetName,
							linkStreetName:linkStreetName,
							turnlatlon:sim_turnlatlon,
							streetLatLon:streetLatLon,
							streetDistance:streetDistance,
							streetDistance:streetDistance,
							segmentNumber:segmentNumber
					}
					simpleArr.push(simpleObj);
				}
				var obj = {
						distance:distance,
						duration:duration,
						routelatlon:routelatlon,
						parameters:{
							start:start,
							dest:dest,
							mid:mid,
							style:style
						},
						routes:routesArr,
						simple:simpleArr
				}
				return obj;
			}
			
			//创建起点和终点的marker
			function createFeature(lonlat,type){
				//获取经纬度信息 
				var aLonlat = lonlat.split(","); 
				var oLonlat = new TLngLat(aLonlat[0],aLonlat[1]); 
				//icon图标URL 
				var sIconImgUrl = null; 
				//icon图标大小new TSize(44,34); 
				var oIconSize = new TSize(44,34); 
				//icon图标的偏移量 
				var oAnchor = new TPixel(18,35); 
				if(type=="start"){ 
					sIconImgUrl = aMarker[0]; 
				}else if(type=="dest"){ 
					sIconImgUrl = aMarker[1]; 
				} 
				//创建一个Icon对象 
				var icon = new TIcon(sIconImgUrl,oIconSize,{anchor:oAnchor}); 
				//创建marker对象 
				var marker = new TMarker(oLonlat,{"icon":icon}); 
				//记录经纬度对象用于地图缩放到适应比例尺 
				//this.aLngLatAry.push(oLonlat); 
				map.addOverLay(marker); 
				return marker; 
			}
			
			//清除地图上的信息及列表信息。
			function clearAll(){
				map.clearOverLays();
				$("#searchDiv").html("");
				$("#pageDiv").html("");
				$("#resultDiv").hide();
			}
			
			////
			
			//将下部的信息提交，添加一条business_travel
			function addItem(){
				if($("#starttime").val()==""){
					alert("先设定开始时间！");
					return ;
				}else if($("#startplace").val()==""||$("#endplace").val()==""||
						$("#daytime").val()==""||$("#distance").val()==""){
							alert("部分路线信息未完善！");
							return ;
				}else{
					var table = document.getElementById("myTable");
					row = table.insertRow(-1);
					startplacecell = row.insertCell(0);
					endplacecell = row.insertCell(1);
					daytimecell = row.insertCell(2);
					distancecell = row.insertCell(3);
					deletecell = row.insertCell(4);
					
					startplacecell.innerHTML = "<input type='hidden' name='routeList["+trindex+"].startPlace' value='"+$("#startplace").val()+"' />"+$("#startplace").val();
					endplacecell.innerHTML = "<input type='hidden' name='routeList["+trindex+"].endPlace' value='"+$("#endplace").val()+"' />"+$("#endplace").val();
					daytimecell.innerHTML = "<input type='hidden' name='routeList["+trindex+"].time' value='"+$("#daytime").val()+"' />"+$("#daytime").val();
					distancecell.innerHTML = "<input type='hidden' name='routeList["+trindex+"].distance' value='"+$("#distance").val()+"' />"+$("#distance").val();
					deletecell.innerHTML = "<input type='button' name='deletebt' class='button white' value='删除' onclick=deletetableitem(this) />";
					
					
					trindex = trindex+1;
					
					//增加一条了，就要将延迟结束日期
					var sd = new Date($("#starttime").val());
					//这里要做个判断处理！
					duration = duration+parseInt($("#daytime").val());
					var enddate = sd.getTime()+(duration*24*60*60*1000);
					sd.setTime(enddate);
					$("#endtime").val(sd.getFullYear()+"-"+(sd.getMonth()+1)+"-"+sd.getDate());
					//
					
					//把下部的信息清空
					$("#startplace").val("");
					$("#endplace").val("");
					$("#daytime").val("");
					$("#distance").val("");
					
					return ;
				}
			}
			
			//删除
			function deletetableitem(obj){	//obj--删除button
				//获得该行
				
				var table = document.getElementById("myTable");
				var index = obj.parentNode.parentNode.rowIndex;		//button.td.tr
				
				//删除一条了，就要将结束日期推前
				var ed = new Date($("#endtime").val());	//获得结束时间
				var day = parseInt(table.rows[index].cells[2].firstChild.value);	//需要减去的天数
				
				duration -= day;
				var enddate = ed.getTime()-(day*24*60*60*1000);
				ed.setTime(enddate);
				$("#endtime").val(ed.getFullYear()+"-"+(ed.getMonth()+1)+"-"+ed.getDate());
				//
				
				table.deleteRow(index);
				//index-1，example:index为2被删，在他下方的本为3，最后改为3-1=2
				for(i=index;i<table.rows.length;i++){
					table.rows[i].cells[0].firstChild.name = "routeList["+(i-1)+"].startPlace";
					table.rows[i].cells[1].firstChild.name = "routeList["+(i-1)+"].endPlace";
					table.rows[i].cells[2].firstChild.name = "routeList["+(i-1)+"].time";
					table.rows[i].cells[3].firstChild.name = "routeList["+(i-1)+"].distance";
				}
				//减1，在再增加时就不会混乱。。
				trindex = trindex-1;
				
			}
			
			//全部删除
			function resetroute(){
				$("#starttime").val("");
				$("#endtime").val("");
				var table = document.getElementById("myTable");
				var length = table.rows.length;
				for(i=1;i<length;i++){
					table.deleteRow(i);
					length = length-1;
					i = i-1;
				}
				trindex = 0;	//清零
				duration = 0;	//清零
			}
			
			
			/*$("#starttime").blur(function(){	//改变starttime就要改变endtime
				if($("#starttime").val()!=""){		//10-26修改
					var date = new Date($("#starttime").val());
					var ed = new Date();
					ed.setTime(date.getTime()+(duration*24*60*60*1000));
					$("#endtime").val(ed.getFullYear()+"-"+(ed.getMonth()+1)+"-"+ed.getDate());
				}
			});*/
			
			/*$("#starttime").click(function(){
				showCalendar('starttime', 'y-mm-dd');
			});*/
			
			function submitform(type,to){	//10-26修改
				var form = document.getElementById("sform");
				
				var length = document.getElementById("myTable").rows.length-1;
				if(length<1){
					alert("不能提交没有条目的出差记录！");
					return ;
				}
				
				if(type==0){
					form.action="route!setRoute.action";
    				form.submit(); 
				}else if(type==1){
					form.action="route!alterRoute.action?sign="+length+"&travelOrder="+to+"";
    				form.submit(); 
				}
			}
			
			function gotopage(){
				if(document.getElementById('pageId').value==''){
					document.getElementById('pageId').value=0;
				} 
				localsearch.gotoPage(parseInt(document.getElementById('pageId').value));
			}
			////
	</script>
<%@ include file="../../footer.jsp" %>
